import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * currencyService - 币种定义Service
 * @date: 2018-7-3

 */
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { parseParameters, isTenantRoleLevel, getCurrentOrganizationId } from 'utils/utils';
var tenantId = getCurrentOrganizationId();

function currencyApi() {
  return isTenantRoleLevel() ? "".concat(tenantId, "/currencys") : "currencys";
}
/**
 * 货币类型查询
 * @async
 * @function queryCurrency
 * @param {object} params - 查询条件
 * @param {?string} params.currencyCode - 币种编码
 * @param {?string} params.currencyName - 币种名称
 * @param {?string} params.countryName - 国家/地区名称
 * @param {!number} [params.page = 0] - 数据页码
 * @param {!number} [params.size = 10] - 分页大小
 * @returns {object} fetch Promise
 */


export function queryCurrency(_x) {
  return _queryCurrency.apply(this, arguments);
}
/**
 * 币种新增
 * @async
 * @function addCurrency
 * @param {object} params.data - 待保存数据
 * @param {!string} params.data.currencyCode - 货币编码
 * @param {!string} params.data.currencyName - 货币名称
 * @param {!string} params.data.countryId - 国家/地区编码
 * @param {!number} params.data.financialPrecision - 财务精度
 * @param {!number} params.data.defaultPrecision - 精度
 * @param {!string} params.data.currencySymbol - 货币符号
 * @param {!number} params.data.enabledFlag - 启用标记
 * @returns {object} fetch Promise
 */

function _queryCurrency() {
  _queryCurrency = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            param = parseParameters(params);
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(currencyApi(params)), {
              method: 'GET',
              query: param
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryCurrency.apply(this, arguments);
}

export function addCurrency(_x2) {
  return _addCurrency.apply(this, arguments);
}
/**
 * 币种编辑
 * @async
 * @function updateCurrency
 * @param {object} params.data - 待保存数据
 * @param {!string} params.data.currencyId - 货币id
 * @param {!string} params.data.currencyCode - 货币编码
 * @param {!string} params.data.currencyName - 货币名称
 * @param {!string} params.data.countryId - 国家/地区编码
 * @param {!number} params.data.financialPrecision - 财务精度
 * @param {!number} params.data.defaultPrecision - 精度
 * @param {!string} params.data.currencySymbol - 货币符号
 * @param {!number} params.data.enabledFlag - 启用标记
 * @returns {object} fetch Promise
 */

function _addCurrency() {
  _addCurrency = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(currencyApi(params)), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _addCurrency.apply(this, arguments);
}

export function updateCurrency(_x3) {
  return _updateCurrency.apply(this, arguments);
}
/**
 * 币种引用明细查询-将废弃
 * @async
 * @function currencyDetail
 * @param {object} params - 查询数据
 * @param {!string} params.currencyId - 货币id
 * @param {!number} [params.page = 0] - 数据页码
 * @param {!number} [params.size = 10] - 分页大小
 * @returns {object} fetch Promise
 */

function _updateCurrency() {
  _updateCurrency = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(currencyApi(params)), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _updateCurrency.apply(this, arguments);
}

export function currencyDetail(_x4) {
  return _currencyDetail.apply(this, arguments);
}
/**
 * 币种引用明细查询
 * @async
 * @function fetchDetail
 * @param {object} params - 查询数据
 * @param {!string} params.currencyId - 货币id
 * @returns {object} fetch Promise
 */

function _currencyDetail() {
  _currencyDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(currencyApi(params), "?tenantId=").concat(params.tenantId), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _currencyDetail.apply(this, arguments);
}

export function fetchDetail(_x5) {
  return _fetchDetail.apply(this, arguments);
}

function _fetchDetail() {
  _fetchDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(currencyApi(params), "/").concat(params.currencyId), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _fetchDetail.apply(this, arguments);
}